package com.osgc.rf.unit;

import java.sql.Connection;

import org.apache.log4j.Category;

import com.inca.np.gui.control.DBTableModel;
import com.inca.np.util.SelectHelper;

public class SysddlInfo {
	DBTableModel ddl;
	static  protected Category logger = Category.getInstance(SysddlInfo.class);
	public SysddlInfo(DBTableModel ddl) {
		this.ddl = ddl;
	}

	public int getSize() {
		if (ddl == null)
			return 0;
		return ddl.getRowCount();
	}

	public String getValue(int row,String col){
		try {
			return ddl.getItemValue(row, col);
		} catch (Exception e) {}
		return null;
	}
	

	// "WMS_IN_QUALITY_FLAG" "WMS_IN_CHECK_FLAG"
	public String getName(String id) {
		if (ddl == null)
			return id;
		for (int i = 0; i < ddl.getRowCount(); i++) {
			if (ddl.getItemValue(i, "ddlid").equals(id))
				return ddl.getItemValue(i, "ddlname");
		}
		return id;
	}

	public String getID(String name) {
		if (ddl == null)
			return name;
		for (int i = 0; i < ddl.getRowCount(); i++) {
			if (ddl.getItemValue(i, "ddlname").equals(name))
				return ddl.getItemValue(i, "ddlid");
		}
		return name;
	}

	public static SysddlInfo getInfo(Connection con, String keyword) throws Exception {
		String sql = "select ddlid,ddlname from sys_ddl_all_v where keyword ='"
				+ keyword + "'";
		logger.debug(sql);
		DBTableModel sorttypelist = new SelectHelper(sql).executeSelect(con, 0,
				9999);

		return new SysddlInfo(sorttypelist);

	}

}
